<?php

namespace App\Admin\Controllers;

use App\Admin\Controllers\Controller;
use App\Admin\Filters\BannerFilter;
use App\Admin\Models\Banner;
use App\Admin\Requests\BannerRequest;
use App\Admin\Resources\BannerResource;
use Illuminate\Http\Request;

class BannerController extends Controller
{
    public function index(BannerFilter $filter)
    {
        $banners = Banner::query()
            ->filter($filter)
            ->paginate();

        return $this->ok(BannerResource::collection($banners));
    }

    public function create()
    {
        return $this->ok();
    }

    public function store(BannerRequest $request)
    {
        $inputs = $request->validated();
        $banner = Banner::create($inputs);

        return $this->created(BannerResource::make($banner));
    }

    public function edit(Request $request, Banner $banner)
    {
        return $this->ok(BannerResource::make($banner));
    }

    public function update(BannerRequest $request, Banner $banner)
    {
        $inputs = $request->validated();
        $banner->update($inputs);

        return $this->created(BannerResource::make($banner));
    }

    public function destroy(Banner $banner)
    {
        $banner->delete();
        return $this->noContent();
    }
}
